#include "StdAfx.h"
#include "DLayer.h"
#include "../Actors/DPlayer.h"
#include "../Actors/DBackground.h"
#include "../Engine/DIRenderer.h"
#include "DGame.h"

DLayer::DLayer(boost::shared_ptr<DGame> game, bool bMainLayer /*= false*/)
: m_game(game)
, m_bMainLayer(bMainLayer)
{
}

DLayer::~DLayer(void)
{
}

void DLayer::setBackground(boost::shared_ptr<DBackground> back)
{
    m_background = back;
}

void DLayer::update(float dt)
{
    if(m_background)
    {
        m_background->update(dt);
    }

    if(m_actors.size())
	{
        // update actors
		foreach(boost::shared_ptr<DIActor> actor, m_actors)
		{
			actor->update(dt);
		}
	}

	if(m_bMainLayer)
	{
		m_game.lock()->player()->update(dt);
	}
}

void DLayer::render(boost::shared_ptr<DIRenderer> renderer)
{
    if(m_background)
    {
        renderer->render(m_background);
    }

    if(m_actors.size())
    {
       renderer->render(m_actors);    
    }

	if(m_bMainLayer)
	{
		renderer->render(m_game.lock()->player());
	}
}